Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oc: Make env use PATCH instead of PUT #5819

Merged
merged 1 commit into from
Dec 2, 2015
Merged

oc: Make env use PATCH instead of PUT #5819

merged 1 commit into from
Dec 2, 2015

Conversation

0xmichalis
Copy link
Contributor

Fixes #5287
Fixes #5816

@0xmichalis
Copy link
Contributor Author

I see that the response from the server after PATCH is exactly the same as the GET which means that the patch somehow isn't applied in the server. @deads2k any ideas why this happens in Origin? I tested label in Kubernetes and it works fine.

I1110 12:56:39.868151    2013 debugging.go:99] GET https://localhost:8443/oapi/v1/namespaces/test/deploymentconfigs/database
I1110 12:56:39.868183    2013 debugging.go:106] Request Headers:
I1110 12:56:39.868196    2013 debugging.go:109]     User-Agent: oc/v1.0.8 (linux/amd64) openshift/33ebfef
I1110 12:56:39.868208    2013 debugging.go:109]     Authorization: Bearer AlY7V4Y6e2Ea5sEDQ_jTxUzuPXh2LUaRS_cz2PNwkqE
I1110 12:56:39.870988    2013 debugging.go:124] Response Status: 200 OK in 2 milliseconds
I1110 12:56:39.871401    2013 debugging.go:127] Response Headers:
I1110 12:56:39.871700    2013 debugging.go:130]     Content-Type: application/json
I1110 12:56:39.872012    2013 debugging.go:130]     Date: Tue, 10 Nov 2015 12:56:39 GMT
I1110 12:56:39.872401    2013 debugging.go:130]     Content-Length: 1523
I1110 12:56:39.872677    2013 debugging.go:130]     Cache-Control: no-store
I1110 12:56:39.873080    2013 request.go:796] Response Body: {"kind":"DeploymentConfig","apiVersion":"v1","metadata":{"name":"database","namespace":"test","selfLink":"/oapi/v1/namespaces/test/deploymentconfigs/database","uid":"a6bf81de-8796-11e5-8c7f-080027c5bfa9","resourceVersion":"1054","creationTimestamp":"2015-11-10T10:34:41Z","labels":{"template":"application-template-stibuild"}},"spec":{"strategy":{"type":"Recreate","recreateParams":{"pre":{"failurePolicy":"Abort","execNewPod":{"command":["/bin/true"],"env":[{"name":"CUSTOM_VAR1","value":"custom_value1"}],"containerName":"ruby-helloworld-database"}},"post":{"failurePolicy":"Ignore","execNewPod":{"command":["/bin/false"],"env":[{"name":"CUSTOM_VAR2","value":"custom_value2"}],"containerName":"ruby-helloworld-database"}}},"resources":{}},"triggers":[{"type":"ConfigChange"}],"replicas":1,"selector":{"name":"database"},"template":{"metadata":{"creationTimestamp":null,"labels":{"name":"database"}},"spec":{"containers":[{"name":"ruby-helloworld-database","image":"openshift/mysql-55-centos7:latest","ports":[{"containerPort":3306,"protocol":"TCP"}],"env":[{"name":"MYSQL_USER","value":"userASW"},{"name":"MYSQL_PASSWORD","value":"8I0BvktP"},{"name":"MYSQL_DATABASE","value":"root"}],"resources":{},"terminationMessagePath":"/dev/termination-log","imagePullPolicy":"Always","securityContext":{"capabilities":{},"privileged":false}}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","securityContext":{}}}},"status":{"latestVersion":1,"details":{"causes":[{"type":"ConfigChange"}]}}}
I1110 12:56:39.880074    2013 request.go:533] Request Body: {"Template":{"ControllerTemplate":{"template":{"spec":{"containers":[{"env":[{"name":"MYSQL_USER","value":"userASW"},{"name":"MYSQL_PASSWORD","value":"8I0BvktP"},{"name":"MYSQL_DATABASE","value":"root"},{"name":"NEW","value":"ENV"}],"image":"openshift/mysql-55-centos7:latest","imagePullPolicy":"Always","name":"ruby-helloworld-database","ports":[{"containerPort":3306,"protocol":"TCP"}],"resources":{},"securityContext":{"capabilities":{},"privileged":false},"terminationMessagePath":"/dev/termination-log"}]}}}}}
I1110 12:56:39.880811    2013 debugging.go:99] PATCH https://localhost:8443/oapi/v1/namespaces/test/deploymentconfigs/database
I1110 12:56:39.881191    2013 debugging.go:106] Request Headers:
I1110 12:56:39.881509    2013 debugging.go:109]     Content-Type: application/strategic-merge-patch+json
I1110 12:56:39.881746    2013 debugging.go:109]     User-Agent: oc/v1.0.8 (linux/amd64) openshift/33ebfef
I1110 12:56:39.881968    2013 debugging.go:109]     Authorization: Bearer AlY7V4Y6e2Ea5sEDQ_jTxUzuPXh2LUaRS_cz2PNwkqE
I1110 12:56:39.916782    2013 debugging.go:124] Response Status: 200 OK in 34 milliseconds
I1110 12:56:39.918118    2013 debugging.go:127] Response Headers:
I1110 12:56:39.918246    2013 debugging.go:130]     Cache-Control: no-store
I1110 12:56:39.920118    2013 debugging.go:130]     Content-Type: application/json
I1110 12:56:39.920312    2013 debugging.go:130]     Date: Tue, 10 Nov 2015 12:56:39 GMT
I1110 12:56:39.920380    2013 debugging.go:130]     Content-Length: 1523
I1110 12:56:39.920459    2013 request.go:796] Response Body: {"kind":"DeploymentConfig","apiVersion":"v1","metadata":{"name":"database","namespace":"test","selfLink":"/oapi/v1/namespaces/test/deploymentconfigs/database","uid":"a6bf81de-8796-11e5-8c7f-080027c5bfa9","resourceVersion":"1274","creationTimestamp":"2015-11-10T10:34:41Z","labels":{"template":"application-template-stibuild"}},"spec":{"strategy":{"type":"Recreate","recreateParams":{"pre":{"failurePolicy":"Abort","execNewPod":{"command":["/bin/true"],"env":[{"name":"CUSTOM_VAR1","value":"custom_value1"}],"containerName":"ruby-helloworld-database"}},"post":{"failurePolicy":"Ignore","execNewPod":{"command":["/bin/false"],"env":[{"name":"CUSTOM_VAR2","value":"custom_value2"}],"containerName":"ruby-helloworld-database"}}},"resources":{}},"triggers":[{"type":"ConfigChange"}],"replicas":1,"selector":{"name":"database"},"template":{"metadata":{"creationTimestamp":null,"labels":{"name":"database"}},"spec":{"containers":[{"name":"ruby-helloworld-database","image":"openshift/mysql-55-centos7:latest","ports":[{"containerPort":3306,"protocol":"TCP"}],"env":[{"name":"MYSQL_USER","value":"userASW"},{"name":"MYSQL_PASSWORD","value":"8I0BvktP"},{"name":"MYSQL_DATABASE","value":"root"}],"resources":{},"terminationMessagePath":"/dev/termination-log","imagePullPolicy":"Always","securityContext":{"capabilities":{},"privileged":false}}],"restartPolicy":"Always","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","securityContext":{}}}},"status":{"latestVersion":1,"details":{"causes":[{"type":"ConfigChange"}]}}}
deploymentconfig "database" updated

for _, info := range infos {
oldData := make([][]byte, len(infos))
for i, info := range infos {
old, err := json.Marshal(info.Object)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this even give you versioned JSON? don't you have to use info.Codec to do this (and are you sure that will result in a patch that is valid against the client's API version?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, by using versioned objects this works like a charm.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess Latest() populates VersionedObject from the API, which (maybe?) forces it to the API version the client will use? Can you test this with input from a file containing a v1beta3 object to make sure v1 is used to create the patch and submit to the server?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I still haven't pushed my latest changes. Latest doesn't do that ... most probably..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I will definitely test including your case

@0xmichalis 0xmichalis changed the title [WIP] env: Switch to PATCH env: Switch to PATCH Nov 10, 2015
@0xmichalis
Copy link
Contributor Author

[test]

@0xmichalis
Copy link
Contributor Author

@liggitt ptal

@0xmichalis
Copy link
Contributor Author

UI flake

re[test]

@0xmichalis
Copy link
Contributor Author

error: unable to import image: the default tag "5.7.7" has not been set on repository "library/mysql"
!!! Error in test/cmd/images.sh:80
    '[ "$(oc import-image mysql --from=mysql --confirm | grep "sha256:")" ]' exited with status 1
Call stack:
    1: test/cmd/images.sh:80 main(...)
Exiting with status 1
!!! Error in hack/test-cmd.sh:281
    '${test}' exited with status 1
Call stack:
    1: hack/test-cmd.sh:281 main(...)
Exiting with status 1
[FAIL] !!!!! Test Failed !!!!

re[test]

@0xmichalis
Copy link
Contributor Author

!!! Error in hack/build-images.sh:61
    'docker build -t $1:latest $2' exited with status 1
Call stack:
    1: hack/build-images.sh:61 image(...)
    2: hack/build-images.sh:79 main(...)
Exiting with status 1
make: *** [release] Error 1

failed docker-build flake rere[test]

@0xmichalis 0xmichalis changed the title env: Switch to PATCH oc: Make env use PATCH instead of PUT Nov 18, 2015
@0xmichalis
Copy link
Contributor Author

cc: @fabianofranz @smarterclayton

@0xmichalis
Copy link
Contributor Author

https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/7223/console

Error while running ssh/sudo command: 
set -e
pushd /data/src/github.com/openshift//origin >/dev/null
export PATH=$GOPATH/bin:$PATH

echo '***************************************************'
echo 'Running hack/test-assets.sh...'
time hack/test-assets.sh
echo 'Finished hack/test-assets.sh'
echo '***************************************************'

popd >/dev/null

SSH authentication failed! This is typically caused by the public/private
keypair for the SSH user not being properly set on the guest VM. Please
verify that the guest VM is setup with the proper public key, and that
the private key path for Vagrant is setup properly as well.
...
Error: EC2 Machine is not available
Build step 'Execute a set of scripts' marked build as failure
Finished: FAILURE

cc: @danmcp

re[test]

@@ -232,6 +234,21 @@ func RunEnv(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Comman
if !one && len(resourceVersion) > 0 {
return cmdutil.UsageError(cmd, "--resource-version may only be used with a single resource")
}
// Keep a copy of the original objects prior to updating their environment.
// Used in constructing the patch(es) that will be applied in the server.
oldObjects, err := resource.AsVersionedObjects(infos, outputVersion)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outputVersion := cmdutil.OutputVersion(cmd, clientConfig.Version) ensures we're working with the same version we're going to submit to the server, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily - clientConfig.Version becomes the default if no output
version is provided.

On Nov 19, 2015, at 11:50 AM, Jordan Liggitt notifications@github.com
wrote:

In pkg/cmd/cli/cmd/env.go
#5819 (comment):

@@ -232,6 +234,21 @@ func RunEnv(f *clientcmd.Factory, in io.Reader, out io.Writer, cmd *cobra.Comman
if !one && len(resourceVersion) > 0 {
return cmdutil.UsageError(cmd, "--resource-version may only be used with a single resource")
}

  • // Keep a copy of the original objects prior to updating their environment.
  • // Used in constructing the patch(es) that will be applied in the server.
  • oldObjects, err := resource.AsVersionedObjects(infos, outputVersion)

outputVersion := cmdutil.OutputVersion(cmd, clientConfig.Version) ensures
we're working with the same version we're going to submit to the server,
right?


Reply to this email directly or view it on GitHub
https://github.com/openshift/origin/pull/5819/files#r45364573.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should --output-version or --api-version be used to decide the version we base patches on?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be using clientConfig.Version to build oldObjects and oldData, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, forgot to switch this. Updated.

@openshift-bot openshift-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 21, 2015
@0xmichalis
Copy link
Contributor Author

[test]

@0xmichalis
Copy link
Contributor Author

@liggitt tests added, ptal

@@ -16,8 +16,14 @@ oc create -f test/integration/fixtures/test-deployment-config.json
oc describe deploymentConfigs test-deployment-config
[ "$(oc get dc -o name | grep 'deploymentconfig/test-deployment-config')" ]
[ "$(oc describe dc test-deployment-config | grep 'deploymentconfig=test-deployment-config')" ]
# Patch a nil list
oc env dc/test-deployment-config TEST=value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add checks to make sure the env command 1) actually took effect and 2) didn't change anything else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did 1, not sure how to check for 2

@openshift-bot openshift-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 24, 2015
@@ -31,6 +31,19 @@ function os::cmd::expect_success_and_text() {
os::cmd::internal::expect_exit_code_run_grep "${cmd}" "os::cmd::internal::success_func" "${expected_text}"
}

# expect_success_and_multiple_text runs the cmd and expects an exit code of 0
# as well as running a grep test to find the given strings in the output
# TODO: Run the command once and not for every string.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to run once, grep multiple before this can merge

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the todo message

or did you mean to actually implement it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually implement it... we can't assume the command is side-effect free

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you don't want to implement it now, that's fine, just run multiple expect_success_and_text calls in the test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, updated to run multiple calls

@0xmichalis
Copy link
Contributor Author

@liggitt anything else tbd here?

if len(outputFormat) != 0 {
objects, err := resource.AsVersionedObjects(infos, outputVersion)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the only place outputVersion should be used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right

@0xmichalis
Copy link
Contributor Author

Never seen this before (#6137)

--- FAIL: TestTranslateTimestamp (0.00s)
    resource_printer_test.go:1222: On months ago, expected '92d', but got '91d'
FAIL
coverage: 50.9% of statements
FAIL    github.com/openshift/origin/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl 0.353s

@0xmichalis
Copy link
Contributor Author

re[test]

@smarterclayton
Copy link
Contributor

Yuck, time zone bug. Tests will fail. Spawn an issue.

On Dec 1, 2015, at 5:42 AM, Michail Kargakis notifications@github.com
wrote:

Never seen this before

--- FAIL: TestTranslateTimestamp (0.00s)
resource_printer_test.go:1222: On months ago, expected '92d', but got '91d'
FAIL
coverage: 50.9% of statements
FAIL github.com/openshift/origin/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl
0.353s


Reply to this email directly or view it on GitHub
#5819 (comment).

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 0c57b08

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/7569/)

@0xmichalis
Copy link
Contributor Author

@liggitt can we merge this now?

@liggitt
Copy link
Contributor

liggitt commented Dec 1, 2015

yup, LGTM

@0xmichalis
Copy link
Contributor Author

[merge]

@liggitt
Copy link
Contributor

liggitt commented Dec 1, 2015

Mentioned API version negotiation issue in #5216 (comment)

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_origin/4207/) (Image: devenv-rhel7_2851)

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 0c57b08

openshift-bot pushed a commit that referenced this pull request Dec 2, 2015
@openshift-bot openshift-bot merged commit 5162e93 into openshift:master Dec 2, 2015
@0xmichalis 0xmichalis deleted the use-patch-in-oc-env branch December 2, 2015 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants